from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-07 14:02:27.051140
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 07, Mar, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4189
Nobs: 588.000 HQIC: -48.8278
Log likelihood: 7013.09 FPE: 4.79737e-22
AIC: -49.0888 Det(Omega_mle): 4.12181e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351248 0.067621 5.194 0.000
L1.Burgenland 0.108325 0.041045 2.639 0.008
L1.Kärnten -0.110639 0.021436 -5.161 0.000
L1.Niederösterreich 0.191256 0.085783 2.230 0.026
L1.Oberösterreich 0.122710 0.084681 1.449 0.147
L1.Salzburg 0.257821 0.043503 5.926 0.000
L1.Steiermark 0.036906 0.057445 0.642 0.521
L1.Tirol 0.101973 0.046385 2.198 0.028
L1.Vorarlberg -0.068465 0.040901 -1.674 0.094
L1.Wien 0.016093 0.075310 0.214 0.831
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051774 0.145509 0.356 0.722
L1.Burgenland -0.037696 0.088321 -0.427 0.670
L1.Kärnten 0.041817 0.046127 0.907 0.365
L1.Niederösterreich -0.204298 0.184589 -1.107 0.268
L1.Oberösterreich 0.458223 0.182218 2.515 0.012
L1.Salzburg 0.282451 0.093611 3.017 0.003
L1.Steiermark 0.113623 0.123611 0.919 0.358
L1.Tirol 0.304557 0.099812 3.051 0.002
L1.Vorarlberg 0.026132 0.088011 0.297 0.767
L1.Wien -0.027451 0.162053 -0.169 0.865
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200387 0.034494 5.809 0.000
L1.Burgenland 0.088569 0.020937 4.230 0.000
L1.Kärnten -0.007287 0.010935 -0.666 0.505
L1.Niederösterreich 0.239845 0.043758 5.481 0.000
L1.Oberösterreich 0.161206 0.043196 3.732 0.000
L1.Salzburg 0.040176 0.022191 1.810 0.070
L1.Steiermark 0.025888 0.029303 0.883 0.377
L1.Tirol 0.081977 0.023661 3.465 0.001
L1.Vorarlberg 0.053673 0.020864 2.573 0.010
L1.Wien 0.117673 0.038416 3.063 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119852 0.034491 3.475 0.001
L1.Burgenland 0.042144 0.020935 2.013 0.044
L1.Kärnten -0.013122 0.010934 -1.200 0.230
L1.Niederösterreich 0.170591 0.043754 3.899 0.000
L1.Oberösterreich 0.337945 0.043192 7.824 0.000
L1.Salzburg 0.100024 0.022189 4.508 0.000
L1.Steiermark 0.110106 0.029300 3.758 0.000
L1.Tirol 0.089834 0.023659 3.797 0.000
L1.Vorarlberg 0.060452 0.020862 2.898 0.004
L1.Wien -0.018153 0.038412 -0.473 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124952 0.064890 1.926 0.054
L1.Burgenland -0.044530 0.039387 -1.131 0.258
L1.Kärnten -0.045428 0.020571 -2.208 0.027
L1.Niederösterreich 0.135534 0.082318 1.646 0.100
L1.Oberösterreich 0.162311 0.081261 1.997 0.046
L1.Salzburg 0.284719 0.041746 6.820 0.000
L1.Steiermark 0.058224 0.055125 1.056 0.291
L1.Tirol 0.157590 0.044511 3.540 0.000
L1.Vorarlberg 0.096968 0.039249 2.471 0.013
L1.Wien 0.072788 0.072268 1.007 0.314
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079116 0.050589 1.564 0.118
L1.Burgenland 0.024984 0.030706 0.814 0.416
L1.Kärnten 0.053281 0.016037 3.322 0.001
L1.Niederösterreich 0.188795 0.064175 2.942 0.003
L1.Oberösterreich 0.332524 0.063351 5.249 0.000
L1.Salzburg 0.034031 0.032546 1.046 0.296
L1.Steiermark 0.006958 0.042975 0.162 0.871
L1.Tirol 0.119203 0.034701 3.435 0.001
L1.Vorarlberg 0.065329 0.030598 2.135 0.033
L1.Wien 0.097733 0.056340 1.735 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171297 0.061062 2.805 0.005
L1.Burgenland 0.004909 0.037063 0.132 0.895
L1.Kärnten -0.065943 0.019357 -3.407 0.001
L1.Niederösterreich -0.106950 0.077461 -1.381 0.167
L1.Oberösterreich 0.209271 0.076467 2.737 0.006
L1.Salzburg 0.054235 0.039283 1.381 0.167
L1.Steiermark 0.247176 0.051873 4.765 0.000
L1.Tirol 0.499637 0.041885 11.929 0.000
L1.Vorarlberg 0.064187 0.036933 1.738 0.082
L1.Wien -0.074622 0.068004 -1.097 0.273
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161632 0.067735 2.386 0.017
L1.Burgenland -0.002401 0.041114 -0.058 0.953
L1.Kärnten 0.062892 0.021472 2.929 0.003
L1.Niederösterreich 0.165908 0.085926 1.931 0.054
L1.Oberösterreich -0.054943 0.084823 -0.648 0.517
L1.Salzburg 0.208663 0.043576 4.788 0.000
L1.Steiermark 0.138262 0.057541 2.403 0.016
L1.Tirol 0.055776 0.046463 1.200 0.230
L1.Vorarlberg 0.146726 0.040969 3.581 0.000
L1.Wien 0.120607 0.075436 1.599 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392131 0.039783 9.857 0.000
L1.Burgenland -0.003992 0.024147 -0.165 0.869
L1.Kärnten -0.021128 0.012611 -1.675 0.094
L1.Niederösterreich 0.200208 0.050467 3.967 0.000
L1.Oberösterreich 0.230193 0.049819 4.621 0.000
L1.Salzburg 0.037160 0.025594 1.452 0.147
L1.Steiermark -0.016570 0.033796 -0.490 0.624
L1.Tirol 0.090369 0.027289 3.312 0.001
L1.Vorarlberg 0.050747 0.024062 2.109 0.035
L1.Wien 0.043684 0.044306 0.986 0.324
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036612 0.103037 0.167870 0.138184 0.095340 0.080539 0.032186 0.209291
Kärnten 0.036612 1.000000 -0.027779 0.131585 0.048286 0.084866 0.443634 -0.067194 0.089314
Niederösterreich 0.103037 -0.027779 1.000000 0.311032 0.118299 0.270201 0.065664 0.151493 0.288224
Oberösterreich 0.167870 0.131585 0.311032 1.000000 0.212155 0.294331 0.166534 0.135569 0.235244
Salzburg 0.138184 0.048286 0.118299 0.212155 1.000000 0.122167 0.090788 0.104335 0.123110
Steiermark 0.095340 0.084866 0.270201 0.294331 0.122167 1.000000 0.134034 0.106101 0.033347
Tirol 0.080539 0.443634 0.065664 0.166534 0.090788 0.134034 1.000000 0.063057 0.150828
Vorarlberg 0.032186 -0.067194 0.151493 0.135569 0.104335 0.106101 0.063057 1.000000 -0.005156
Wien 0.209291 0.089314 0.288224 0.235244 0.123110 0.033347 0.150828 -0.005156 1.000000